inspector,http: support builtin http request bodies#62915
Open
GrinZero wants to merge 5 commits intonodejs:mainfrom
Open
inspector,http: support builtin http request bodies#62915GrinZero wants to merge 5 commits intonodejs:mainfrom
GrinZero wants to merge 5 commits intonodejs:mainfrom
Conversation
Signed-off-by: GrinZero <774933704@qq.com>
Collaborator
|
Review requested:
|
Author
metcoder95
approved these changes
Apr 24, 2026
Member
metcoder95
left a comment
There was a problem hiding this comment.
lgtm, it just seems that is gonna need a documentation for the new dcs
…w-dcs doc: add HTTP body chunk events to diagnostics_channel docs
Author
|
Thanks for the feedback. I’ve updated the documentation in Specifically, I added/updated entries for:
I also aligned the wording and structure with the existing Node.js docs style for built-in channels. |
…w-dcs-nkmamj Document HTTP body chunk diagnostics and update inspector network test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR adds builtin
http/httpsrequest-body support to network inspection, soNetwork.getRequestPostDataworks for text request bodies while preserving the existing rejection behavior for binary request bodies.It also moves builtin
httpresponse-body tracking to a raw-byte hook beforeIncomingMessagedecoding, so response inspection remains correct even when user code callsresponse.setEncoding(...).This closes part of the remaining
postDatagap tracked in the network-inspection stabilization issue.Problem
Builtin
http/httpsnetwork inspection currently emits:Network.requestWillBeSentNetwork.responseReceivedNetwork.loadingFinishedHowever, it does not emit request-body data for the builtin
httpclient path. As a result,Network.getRequestPostDatacannot return POST data for builtinhttp/httpsrequests.In the tracking issue for stabilizing network inspection, builtin
http/httpsrequestpostDatais still marked as needing further investigation. This change targets that specific gap.While working on that, this PR also addresses an important response-side edge case: listening to
IncomingMessage'data'events is not a stable source of raw bytes.When user code calls:
the chunks observed by userland change from
Bufferobjects into strings. The inspector protocol expects byte-oriented payloads forNetwork.dataReceivedandNetwork.dataSent, so reconstructing bytes from already-decoded strings is only a best-effort fallback and can lose the original payload.Approach
1. Reuse the existing request buffering pipeline
This change does not modify the CDP schema or the C++ buffering logic in
NetworkAgent.Instead, it reuses the existing pipeline already used by other transports:
2. Add builtin
httprequest-body diagnostics eventsThe builtin
httpclient now publishes:http.client.request.bodyChunkSenthttp.client.request.bodySentThese events are emitted from the
ClientRequestwrite path before HTTP framing is applied, so the inspector sees the original user payload rather than chunked-transfer framing bytes.That makes the behavior consistent with the existing
undiciandhttp2network-inspection implementations.3. Capture builtin
httpresponse bytes before decodingFor responses, this PR intentionally avoids relying on
IncomingMessage.on('data')innetwork_http.js.Instead, it adds:
http.client.response.bodyChunkReceivedfrom the HTTP parser body callback in
_http_common.js.That hook runs before
Readable.setEncoding()transforms chunks for userland, so the inspector always receives raw bytes. This avoids issues such as:dataLengthor wrong event shape when user code receives stringsNetwork.dataReceived4. Prefer raw bytes over string re-encoding
A temporary compatibility fix could convert string chunks back into
Buffers, but that is not equivalent to preserving the original bytes:setEncoding()are no longer raw bytesSo the final implementation moves the builtin
httpresponse path to the same principle used by external tooling: capture bytes first, decode later if needed.This is also consistent with the general handling in
node-network-devtools, where network payload processing is built aroundBufferdata rather than post-decoding string chunks.Behavior
After this change:
httpandhttpsPOST requests with UTF-8 text bodies are available throughNetwork.getRequestPostDatahttpresponse inspection continues to work even if user code callsresponse.setEncoding('utf8')Tests
This PR adds and extends coverage in:
test/parallel/test-diagnostics-channel-http.jstest/parallel/test-inspector-network-http.jsThe updated tests cover:
write()andend()httpandhttpsNetwork.getRequestPostDatafor text bodiesresponse.setEncoding('utf8')Verification
Verified locally with:
Both tests passed locally with the built
out/Release/node.Refs